﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using Lx.Web.Common.ControlsUI;
using BLF.WWW_WWW.Files;
using Model.WWW_WWW.files;
using System.Collections;

namespace Web.Control.WWW.files
{
    public class File : BaseControl
    {
        /// <summary>
        /// 相关文档列表
        /// </summary>
        public List<FileDocModel> FModel = null;
        /// <summary>
        /// 评论列表
        /// </summary>
        public List<DocCommentModel> CModel = new List<DocCommentModel>();
        /// <summary>
        /// 文件信息
        /// </summary>
        public FileDocModel DocModel = null;
        public List<string> TagList = new List<string>();
        /// <summary>
        /// 用户是否喜欢过这个文件(bool true:有记录 false:无记录)
        /// </summary>
        protected bool IsLike = false;
        /// <summary>
        /// 文件的级别1.Beginner；2.Basic；3.Intermediate；4.Advanced；(累加)
        /// </summary>
        protected string FileLevel = "";
        protected override void OnLoad(EventArgs e)
        {
            //    0：该文件信息(FileDocModel)、1：评论列表(DocCommentModel List)、
            // 2：相关文档列表(FileDocModel List)、3：文件tag列表(string List)、
            // 4：用户是否喜欢过这个文件(bool true:有记录 false:无记录)
            string sessionID = Session.SessionID;
            string iP = Request.UserHostAddress;
            string userAgent = Request.UserAgent;
            string referer = HttpContext.Current.Request.UrlReferrer == null ? "" : HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
            ArrayList arrList = BLF.WWW_WWW.Files.Files.GetAFile(Request.QueryString["guid"], 5, 10, sessionID, iP, userAgent, referer, HttpContext.Current.User.Identity.Name);
            if (arrList != null)
            {
                DocModel = arrList[0] as FileDocModel;
                TagList = arrList[3] as List<string>;
                CModel = arrList[1] as List<DocCommentModel>;
                FModel = arrList[2] as List<FileDocModel>;

                //浏览器标题
                string tags = "";
                for (int i = TagList.Count - 1; i >= 0; i--)
                {
                    tags += TagList[i] + ", ";
                }                
                this.DynamicTitle = GetText("SF530", new string[] { DocModel.Title, GetLanguageText(DocModel.LanguageLearn), GetLanguageText(DocModel.BaseLanguage) });
                this.DynamicKeywords = GetText("SF531", new string[] { tags, GetLanguageText(DocModel.LanguageLearn), GetLanguageText(DocModel.BaseLanguage) });
                this.DynamicDescription = GetText("SF532", new string[] { DocModel.Title });

                IsLike = (bool)arrList[4];
                string[] leaveArr = DocModel.Level.Split(',');
                for (int i = leaveArr.Length - 1; i >= 0; i--)
                {
                    switch (leaveArr[i])
                    {
                        case "1":
                            FileLevel += GetText("C0019");
                            break;
                        case "2":
                            FileLevel += GetText("C0020");
                            break;
                        case "3":
                            FileLevel += GetText("C0021");
                            break;
                        case "4":
                            FileLevel += GetText("C0022");
                            break;
                    }
                    if (i != 0) FileLevel += ", ";

                }
            }
            else {
                Response.Write("error!");
            }
            base.OnLoad(e);
        }
    }
}